import 'package:flutter/material.dart';
import 'package:shopping_group/modle/more/entity/group_detail_entity.dart';
import 'package:shopping_group/modle/play/ui/pingtuan_paly_page.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/object_util.dart';
import 'package:shopping_group/utils/route_util.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class MoreToPalyPage extends StatefulWidget {
  final GroupDetailEntity entity;
  MoreToPalyPage({Key key, @required this.entity}) : super(key: key);

  @override
  _MoreToPalyPageState createState() => _MoreToPalyPageState();
}

class _MoreToPalyPageState extends State<MoreToPalyPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: WidgetUtils.showAppar(context, '确认推广'),
      body: Container(
        height: double.infinity,
        decoration: BoxDecoration(
          color: Colours.gray_f0,
        ),
        child: Column(
          children: <Widget>[
            Expanded(
              child: SingleChildScrollView(
                scrollDirection: Axis.vertical,
                reverse: false,
                padding: EdgeInsets.all(0.0),
                physics: BouncingScrollPhysics(),
                child: Column(
                  children: <Widget>[
                    _shoppingView(),
                    SizedBox(
                      height: 8,
                    ),
                    _hdgzView(),
                  ],
                ),
              ),
            ),
            _bottomView(),
          ],
        ),
      ),
    );
  }

  Widget _hdgzView() {
    return Container(
      alignment: Alignment.center,
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
      decoration: new BoxDecoration(
        color: Colours.title_white,
      ),
      margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 0),
      child: Column(
        children: <Widget>[
          WidgetUtils.getTextColorView(
              '活动规则', Colours.text_2222, Dimens.FONT_SIZE_16),
          SizedBox(
            height: 16,
          ),
          FadeInImage.assetNetwork(
            image: this.widget.entity.remark,
            placeholder: 'images/picture_loading.png',
            fit: BoxFit.fill,
          ),
        ],
      ),
    );
  }

  Widget _bottomView() {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.only(top: 0),
      child: Row(
        children: <Widget>[
          Expanded(
            flex: 1,
            child: GestureDetector(
              onTap: () {
                // RouteUtil.closeView();
              },
              child: Container(
                alignment: FractionalOffset.center,
                height: 54,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    WidgetUtils.getTextColorView(
                        '总额：', Colors.white, Dimens.FONT_SIZE_14,
                        fontweight: FontWeight.w500),
                    WidgetUtils.getTextColorView(
                        '¥${this.widget.entity.realCharge}',
                        Colours.themeColor,
                        Dimens.FONT_SIZE_14,
                        fontweight: FontWeight.w500),
                  ],
                ),
                decoration: BoxDecoration(
                  // borderRadius: BorderRadius.circular(10),
                  color: Colours.blackground_black_239,
                ),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: GestureDetector(
              onTap: () {
                RouteUtil.goParameter(
                    PingtuanPalyPage(entity: this.widget.entity));
              },
              child: Container(
                alignment: FractionalOffset.center,
                height: 54,
                child: WidgetUtils.getTextColorView(
                    '提交代理券', Colors.white, Dimens.FONT_SIZE_12,
                    fontweight: FontWeight.w500),
                decoration: BoxDecoration(
                  // borderRadius: BorderRadius.circular(10),
                  color: Colours.text_9C1,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _shoppingView() {
    return Container(
      decoration: BoxDecoration(
        color: Colours.title_white,
      ),
      padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 8),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Container(
              height: 110.0,
              width: 110.0,
              child: FadeInImage.assetNetwork(
                image: this.widget.entity.imgUrl,
                placeholder: 'images/picture_loading.png' /* 指定gif */,
                fit: BoxFit.contain,
              ),
            ),
            flex: 2,
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.only(left: 16),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  WidgetUtils.getTextColorView(
                    '${_getType(this.widget.entity)}元${this.widget.entity.sucMenCt}人推广',
                    Colours.text_2222,
                    Dimens.FONT_SIZE_14,
                  ),
                  SizedBox(
                    height: Dimens.FONT_SIZE_16,
                  ),
                  WidgetUtils.getTextColorView(
                    '注意：\n提交相关金额代理卷\n获得相应资格推广权',
                    Colours.gray_91,
                    Dimens.FONT_SIZE_14,
                  ),
                  SizedBox(
                    height: 8,
                  ),
                  // WidgetUtils.getTextColorView(
                  //   '¥${this.widget.entity.realCharge} 共1件商品',
                  //   Colours.themeColor,
                  //   Dimens.FONT_SIZE_14,
                  // ),
                ],
              ),
            ),
            flex: 3,
          ),
        ],
      ),
    );
  }

  String _getType(GroupDetailEntity entity) {
    String type = '99';
    if (ObjectUtil.isEmptyString(entity.groupSpecType)) {
      return type;
    }

    List<String> list = entity.groupSpecType.split('_');
    if (ObjectUtil.isEmptyList(list) || 1 == list.length) {
      return type;
    }

    return list[1];
  }

  @override
  void dispose() {
    super.dispose();
  }
}
